//
//  HaveVIdeoTrainVM.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/6/15.
//

import Foundation
import Moya

enum HaveVideoTrainVM {
    case startVideoTask(planId:String,userPlanId:String)
    case endTrainTask(userPlanId:String)
    case getmusicListStartOrEnd
}

extension HaveVideoTrainVM:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .startVideoTask:
            return "api/admin/planForApp/startUserPlan"
        case .endTrainTask:
            return "api/admin/planForApp/finishUserPlan"
        case .getmusicListStartOrEnd:
            return "api/admin/planForApp/getExerRemarkVoice"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .startVideoTask:
            return .post
        case .endTrainTask:
            return .post
        case .getmusicListStartOrEnd:
            return .get
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    var task: Task {
        switch self {
        case let .startVideoTask(planId, userPlanId):
            
            var paramer:[String:Any] = [:]
            
            if planId.isEmpty == false {
                paramer["planId"] = planId
            }
            
            if userPlanId.isEmpty == false {
                paramer["userPlanId"] = userPlanId
            }
            
            return .requestParameters(parameters: paramer, encoding: JSONEncoding.default)
        case let .endTrainTask(userPlanId):
            return .requestParameters(parameters: ["userPlanId":userPlanId], encoding: JSONEncoding.default)
            
        case .getmusicListStartOrEnd:
            return .requestPlain
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
}
